public class Test {
    public static void main(String[] args) {
        //创建Dog对象
        Dog dog1 = new Dog();
        dog1.bark();
        dog1.name = "Bart";

        //创建Dog数组
        Dog[] MyDogs = new Dog[3];
        //关门放狗
        MyDogs[0] = new Dog();
        MyDogs[1] = new Dog();
        MyDogs[2] = dog1;

        //通过数组引用存取Dog
        MyDogs[0].name = "Fred";
        MyDogs[1].name = "Marge";

        //MyDog[2]的名字是？
        System.out.print("last dog's name is ");
        System.out.println(MyDogs[2].name);

        //逐个对Dog执行bark()
        int x = 0;
        while(x < MyDogs.length){
            MyDogs[x].bark();
            x = x+1;
        }
    }
}
